package com.blq.api.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.blq.api.service.IEvaluationBackupService;
import com.blq.common.annotation.Log;
import com.blq.common.annotation.RepeatSubmit;
import com.blq.common.core.controller.BaseController;
import com.blq.common.core.domain.PageQuery;
import com.blq.common.core.domain.R;
import com.blq.common.core.page.TableDataInfo;
import com.blq.common.core.validate.AddGroup;
import com.blq.common.core.validate.EditGroup;
import com.blq.common.enums.BusinessType;
import com.blq.common.utils.poi.ExcelUtil;
import com.blq.api.domain.Bo.EvaluationBackupBo;
import com.blq.api.domain.Vo.EvaluationBackupVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 评价备份Controller
 *
 * @author Blq
 * @date 2023-02-01
 */
@Validated
@Api(value = "评价备份控制器", tags = {"评价备份管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/web/backup")
public class EvaluationBackupController extends BaseController {

    private final IEvaluationBackupService iEvaluationBackupService;

    /**
     * 查询评价备份列表
     */
    @ApiOperation("查询评价备份列表")
    @SaCheckPermission("web:backup:list")
    @GetMapping("/list")
    public TableDataInfo<EvaluationBackupVo> list(EvaluationBackupBo bo, PageQuery pageQuery) {
        return iEvaluationBackupService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出评价备份列表
     */
    @ApiOperation("导出评价备份列表")
    @SaCheckPermission("web:backup:export")
    @Log(title = "评价备份", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EvaluationBackupBo bo, HttpServletResponse response) {
        List<EvaluationBackupVo> list = iEvaluationBackupService.queryList(bo);
        ExcelUtil.exportExcel(list, "评价备份", EvaluationBackupVo.class, response);
    }

    /**
     * 获取评价备份详细信息
     */
    @ApiOperation("获取评价备份详细信息")
    @SaCheckPermission("web:backup:query")
    @GetMapping("/{evaluationId}")
    public R<EvaluationBackupVo> getInfo(@ApiParam("主键")
                                         @NotNull(message = "主键不能为空")
                                         @PathVariable("evaluationId") String evaluationId) {
        return R.ok(iEvaluationBackupService.queryById(evaluationId));
    }

    /**
     * 新增评价备份
     */
    @ApiOperation("新增评价备份")
    @SaCheckPermission("web:backup:add")
    @Log(title = "评价备份", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EvaluationBackupBo bo) {
        return toAjax(iEvaluationBackupService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改评价备份
     */
    @ApiOperation("修改评价备份")
    @SaCheckPermission("web:backup:edit")
    @Log(title = "评价备份", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EvaluationBackupBo bo) {
        return toAjax(iEvaluationBackupService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除评价备份
     */
    @ApiOperation("删除评价备份")
    @SaCheckPermission("web:backup:remove")
    @Log(title = "评价备份", businessType = BusinessType.DELETE)
    @DeleteMapping("/{evaluationIds}")
    public R<Void> remove(@ApiParam("主键串")
                          @NotEmpty(message = "主键不能为空")
                          @PathVariable String[] evaluationIds) {
        return toAjax(iEvaluationBackupService.deleteWithValidByIds(Arrays.asList(evaluationIds), true) ? 1 : 0);
    }
}
